package router

import (
	v1 "gin-project/api/v1"
	"gin-project/middleware"
	"gin-project/model"
	"gin-project/utils"
	"github.com/gin-gonic/gin"
)

func InitRouter() {
	model.InitDb()
	gin.SetMode(utils.AppMode)

	r := gin.Default()
	r.Use(middleware.Cors())

	r.Static("/static", "dist/static")
	r.LoadHTMLGlob("dist/index.html")
	r.GET("/", func(c *gin.Context) {
		c.HTML(200, "index.html", nil)
	})

	router := r.Group("/api/v1/admin")
	{
		router.POST("/login", v1.AdminLogin)
	}

	v1Auth := r.Group("/api/v1/admin")
	{
		// 歌手
		v1Auth.POST("/singer/add", v1.InsertSinger)
		v1Auth.GET("/singer/allSinger", v1.SelectSingers)
		v1Auth.POST("/singer/updateSingerPic", v1.UpdateSingerPic)
		v1Auth.POST("/singer/update", v1.UpdateSinger)
		v1Auth.GET("/singer/delete", v1.DeleteSinger)

		// 歌曲
		v1Auth.POST("/song/add", v1.InsertSong)
		v1Auth.GET("/song/singer/detail", v1.SelectSongsBySingerID)
		v1Auth.POST("/song/update", v1.UpdateSong)
		v1Auth.GET("/song/delete", v1.DeleteSong)
		v1Auth.POST("/song/updateSongPic", v1.UpdateSongPic)
		v1Auth.POST("/song/updateSongUrl", v1.UpdateSongUrl)
		v1Auth.GET("/song/songOfSongName", v1.SelectSongByName)
		v1Auth.GET("/song/allSong", v1.SelectSongAll)
		v1Auth.GET("/song/likeSongOfName", v1.SelectLikeName)
		v1Auth.GET("/song/detail", v1.SelectSongByID)

		// 歌单
		v1Auth.POST("/songList/add", v1.InsertSongList)
		v1Auth.POST("/songList/update", v1.UpdateSongList)
		v1Auth.POST("/songList/updatePic", v1.UpdateSongListPic)
		v1Auth.GET("/songList/delete", v1.DeleteSongList)
		v1Auth.GET("/songList/allSongList", v1.SelectSongListAll)
		v1Auth.GET("/songList/likeTitle", v1.SelectLikeTitle)
		v1Auth.GET("/listSong/detail", v1.SelectSongsBySongListID)

		// 歌单的歌曲
		v1Auth.POST("/songList/listSong/add", v1.InsertSongToSongList)
		v1Auth.GET("/songList/listSong/detail", v1.SelectSongListOfSongs)
		v1Auth.GET("/songList/listSong/delete", v1.DeleteSongListOfSong)

		// 用户
		v1Auth.POST("/consumer/add", v1.InsertUser)
		v1Auth.GET("/consumer/allConsumer", v1.SelectUserAll)
		v1Auth.POST("/consumer/updatePic", v1.UpdateUserPic)
		v1Auth.POST("/consumer/update", v1.UpdateUser)
		v1Auth.GET("/consumer/delete", v1.DeleteUserByID)
	}



	r.Run(utils.HttpPort)
}
